package pt.compflow.activity.gateway;

import java.util.List;

import pt.compflow.flowontology.model.FlowOntologyModel;
import pt.compflow.flowontology.model.Gateway;
import pt.compflow.tools.Copyable;
import pt.compflow.tools.OntModelHelper;

/**
 * Main Gateway Class. Based on three methods: 
 * 		1) isReady -> checks incoming transitions (depends on type of gateway: sync or merge). 
 * 		2) execute -> business operations upon gateway; does not influence workflow. (user defined)
 * 		3) getEvaluationFilter -> returns a filter that evaluates a transition to an upcoming activity; 
 * 								influences workflow. (user defined)
 * 
 * @author 
 * 
 */
public abstract class GatewayExecutor implements Copyable<GatewayExecutor> {

	protected OntModelHelper ontModelHelper;
	protected FlowOntologyModel jobModel;
	protected Gateway gateway;

	public GatewayExecutor() {
		// empty
	}

	public GatewayExecutor(OntModelHelper ontModelHelper, FlowOntologyModel jobModel, Gateway gateway) {
		setup(ontModelHelper, jobModel, gateway);
	}
	
	public void setup(OntModelHelper ontModelHelper, FlowOntologyModel jobModel, Gateway gateway) {
		this.ontModelHelper = ontModelHelper;
		this.jobModel = jobModel;
		this.gateway = gateway;
	}

	/** Depends on IN conditions **/
	public abstract boolean isReady();

	/** User defined **/
	protected abstract void execute();

	/** Starter method **/
	public final void run() {
		execute();
	}

	public abstract List<String> getNextActivities();

	public FlowOntologyModel getJobModel() {
		return jobModel;
	}

	public void setJobModel(FlowOntologyModel jobModel) {
		this.jobModel = jobModel;
	}

	public Gateway getGateway() {
		return gateway;
	}

	public void setGateway(Gateway gateway) {
		this.gateway = gateway;
	}

}
